﻿
@{
    ViewData["Title"] = "密码生成器";
    Layout = "~/Views/Share/_Layout.cshtml";
}
<link href="~/Lib/Mobile/jquery.mobile-1.4.5.min.css" rel="stylesheet" />
<script src="~/Lib/Mobile/jquery.mobile-1.4.5.min.js"></script>
<script type="text/javascript">
    $(function () {
        MakePass();
    });
    function MakePass() {
        $.ajax({
            type: "post",
            dataType: "json",
            cache: false,
            data: {
                num: $("#num")[0].checked, strLower: $("#strLower")[0].checked, strUpper: $("#strUpper")[0].checked, other: $("#other")[0].checked, count: $("#count").val()
            },
            url: "../../Tool/MakePass",
            async: true,
            success: function (data) {
                if (data.code == 1) {
                    $("#data").text(data.msg);
                }
                else {
                    $("#data").text(data.msg);
                }
            }
        });
    }
    function Copy(ths) {
        const input = document.createElement('input');
        document.body.appendChild(input);
        input.setAttribute('value', $("#data").text());
        input.select();
        if (document.execCommand('copy')) {
            document.execCommand('copy');
            console.log('复制成功');
            ths.innerText = "复制成功";
        }
        document.body.removeChild(input);
    }
</script>
<div style="width:60%; margin:auto;text-align:center;">
    <h2>生成随机密码</h2>
    <label>
        <input type="checkbox" checked="checked" name="checkbox-0" id="num" />小数（0-9）
    </label>
    <label>
        <input type="checkbox" checked="checked" name="checkbox-1" id="strLower" />小写（a-z）
    </label>
    <label>
        <input type="checkbox" checked="checked" name="checkbox-2" id="strUpper" />大写（A-Z）
    </label>
    <label>
        <input type="checkbox" checked="checked" name="checkbox-3" id="other" />特殊符号（!@@#$%^&*）
    </label>
    <label for="count">位数</label><input id="count" type="text" value="16" />
    <button onclick="MakePass();">生成</button>
    <label id="data"></label>
    <button onclick="Copy(this);">复制</button>
</div>

